package org.example.adminservice.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.example.adminservice.SalelogService;
import org.example.mapper.SalelogMapper;
import org.example.pojo.PageBean;
import org.example.pojo.admindto.SaleLogDTO;
import org.example.pojo.entity.SaleLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SalelogServiceImpl implements SalelogService {

    @Autowired
    private SalelogMapper salelogMapper;

    @Override
    public PageBean saleLog(SaleLogDTO saleLogDTO) {
        SaleLog saleLog = new SaleLog();
        saleLog.setUsername(saleLogDTO.getUsername() );
        saleLog.setGoodname(saleLogDTO.getGoodname() );
        saleLog.setState(saleLogDTO.getState() == null ? 0 : saleLogDTO.getState());
        Integer page=saleLogDTO.getPage(),pageSize=saleLogDTO.getPageSize();
        PageHelper.startPage(page,pageSize);
        List<SaleLog> list=salelogMapper.list( saleLog );
        Page<SaleLog> p=(Page<SaleLog>) list;
        PageBean pageBean=new PageBean(p.getTotal(),p.getResult());
        return pageBean;
    }
}
